/**
 * zmn 监控配置
 * 文件命名格式：zmn.模块名称.表名称.功能.js
 * @author chongw
 * @since 019/07/31 13:58
 */
let $;
layui.define(['index', 'table','laydate', 'laypage'], function (exports) {
    $ = layui.$;
    let layer = layui.layer;
    let table = layui.table;
    let laypage = layui.laypage;
    let laydate = layui.laydate;
    let form = layui.form;

    form.render(null, "zmn-form");

    form.verify({
        checkCycle:function () {
            let checked = $("input[name='cycle']:checked");
            if(!checked ||(checked && checked.length <= 0)){
                return "请选择监控周期";
            }
        },
        integer: [
            /^[1-9]\d*$/
            , '只能输入正整数'
        ]
    });

    //时间选择器
    laydate.render({
        elem: '#computeTime'
        ,type: 'time'
    });

    //时间选择器
    laydate.render({
        elem: '#pushTime'
        ,type: 'time'
    });

    // 提交
    form.on('submit(zmn-form-submit)', function(obj){
        let index;
        let data = obj.field;
        let cycleElement = $("input[name='cycle']:checked");
        let cycleArr = new Array();
        $.each(cycleElement,function(){
            cycleArr.push($(this).val());
        })
        let cycle = cycleArr.join(',');
        data.monitorCycle = cycle;
        $.ajax({
            async: false,
            type: "POST",
            url: "/brs/scene/modifyScene.action",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(data),
            beforeSend: function () {
                index = layer.load(1, {
                    shade: [0.5, '#DBDBDB']
                });
            },
            success:function(data) {
                if (data.status === 200) {
                    layer.msg("业务场景修改成功！",{"icon": 1},function (){
                        location.href="/brs/scene/list.action";
                    });
                } else {
                    layer.msg(data.message, {"icon": 2});
                }
                layer.close(index);
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){}
        })
        return false;
    });

    //对外暴露的接口
    exports('scene_info', {});
});



